const fp = require('lodash/fp')
const { Maybe, Container } = require('./support')

// 练习1
let maybe = Maybe.of([5,6,1])
let ex1 = value => {
  let v = maybe.map(fp.map(fp.add(value)))
  console.log(v)
}
ex1(1)

// 练习2
let xs = Container.of(['do','ray','me','fa','so','la','ti','do'])
let ex2 = () => {
  let v = xs.map(fp.first)
  console.log(v)
}
ex2()

// 练习3
let safeProp = fp.curry(function(x, o){
  return Maybe.of(o[x])
})
let user = { id: 2, name: 'Albert'}
let ex3 = () => {
  let v = safeProp('name',user).map(fp.first)
  console.log(v)
}
ex3()

// 练习4
let ex4 = function (n) {
  return Maybe.of(n).map(parseInt)
}
console.log(ex4('1'))